package com.ict.web.dto;

import com.ict.common.utils.DateUtils;
import com.ict.common.utils.SecurityUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.AnnualDeclaration;
import com.ict.web.domain.Notice;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;

/**
 * 公告 dto入参实体
 *
 * @author xss
 * @date 2022-02-16
 */
@Data
@NoArgsConstructor
public class InsertNoticeDto {
    @ApiModelProperty(value = "公告标题")
    private String noticeTitle;

    @ApiModelProperty(value = "公告内容")
    private String noticeContent;

    @ApiModelProperty(value = "公告发送人")
    private String noticeSend;

    @ApiModelProperty(value = "公告附件")
    private YzqFileDTO  noticeFile;

    public static Notice of (InsertNoticeDto dto){
        Notice bean = new Notice();
        BeanUtils.copyProperties(dto,bean);
        //设置公告id
        bean.setNoticeId(IdUtils.snowId());
        //创建时间和更新时间
        bean.setUpdateTime(DateUtils.getNowDate());
        bean.setCreateTime(DateUtils.getNowDate());
        //设置删除状态（默认为0未删除）
        bean.setDelFlag(Notice.DELETE_STATUS_NORMAL);
        //设置操作人
        bean.setNoticeOperator(SecurityUtils.getUsername());
        return bean;
    }

    /**
     * 将insertNoticeDto上传的附件对象转为file
     *
     * @param notice
     * @param dto
     * @return
     */
    public static ArrayList<YzqFile> toFile(Notice notice, InsertNoticeDto dto){
        ArrayList<YzqFile> fileList = new ArrayList<>();
        YzqFileDTO noticeFile = dto.getNoticeFile();

        YzqFile fileNotice = new YzqFile();
        fileNotice.setId(String.valueOf(IdUtils.snowId()));
        BeanUtils.copyProperties(noticeFile,fileNotice);
        fileList.add(fileNotice);
        notice.setNoticeFile(fileNotice.getId());
        return fileList;
    }

}
